//
//  JSONRequest.h
//  nonghubao
//
//  Created by 王 文彬 on 13-1-26.
//  Copyright (c) 2013年 mypocketbaby. All rights reserved.
//


#import <Foundation/Foundation.h>
#import "MBProgressHUD.h"

//HTTP请求的两种类型定义
//Normal = urlencode， MultiPart = multipart
typedef NS_ENUM(NSInteger, RequestMode) {
    RequestModeNormal,
    RequestModeMultiPart
};


//HUD的类型
typedef NS_ENUM(NSInteger, HUDStyleMode) {
    HUDStyleModeTitle = MBProgressHUDModeText,
    HUDStyleModeCustomView = MBProgressHUDModeCustomView
};


//定义的协议
@protocol JSONRequestDelegate <NSObject>

@optional
- (void)requestDidLoadJSON:(NSDictionary *)dict;    //请求成功
- (void)requestFailWithNetworkUnavailabe;    //网络错误

@end



@interface JSONRequest : NSObject
{
    __weak id<JSONRequestDelegate> _delegate;
    NSURL*                  _url;
    NSMutableDictionary*    _requestParameters;
    RequestMode             _requestMode;

    MBProgressHUD*          _hud;
    NSString*               _hudTitle;
    NSString*               _hudDetailText;
    UIView*                 _hudCustomView;
    MBProgressHUDMode       _hudMode;
    BOOL                    _hudOn;
    UIView*                 _hudView;
    
    SEL                     _sucessSelector;
    SEL                     _failSelector;
}

//实例相关
- (id)initWithURLString:(NSString *)URLString;
- (void)setValue:(id)value forParameter:(NSString *)name;

@property (strong, nonatomic) NSString* URLString;
@property (weak, nonatomic)   id<JSONRequestDelegate> delegate;
@property (assign, nonatomic) RequestMode requestMode;
@property (strong, nonatomic, readonly) NSDictionary* requestParameters;


//请求的方式
//- (NSDictionary *)synchronous:(RequestMode)mode withParameters:(NSDictionary *)params;
//- (void)asynchronous:(RequestMode)mode withParameters:(NSDictionary *)params;
- (NSDictionary *)synchronous;
- (void)asynchronous;

//selector
- (void)setSuccessSelector:(SEL)selector delegate:(__weak id)delegate;
- (void)setFailSelector:(SEL)selector delegate:(__weak id)delegate;


//提示相关
- (void)setHUD:(HUDStyleMode)mode withView:(UIView *)view;
@property (nonatomic, strong) NSString* hudTitle;
@property (nonatomic, strong) NSString* hudDetailText;
@property (nonatomic, strong) UIView*   hudCustomView;
@property (nonatomic, assign) BOOL      hudOn;
@property (nonatomic, assign) SEL       successSelector;
@property (nonatomic, assign) SEL       failSelector;

@end
